﻿// Author:					HungNM
// Created:					16-08-2012
// Last Modified:			16-08-2012
//

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using eProject.Business;


namespace eProject.Web.UI
{
    public partial class DefaultPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadParams();
            LoadSettings();
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            if (IsPostBack) return;
            BindDropDownList();
        }

        private void BindDropDownList()
        {
            SiteUtils.BindNumber(10, ddlAdult);
            ListItem item = ddlAdult.Items.FindByValue("1");
            item.Selected = true;
            SiteUtils.BindNumber(10, ddlChildren);
            SiteUtils.BindNumber(10, ddlInfant);
            BindOrigin();
            BindDestination();
        }

        private void BindOrigin()
        {
            ddlOrigin.Items.Clear();
            ddlOrigin.ClearSelection();
            ListItem item = new ListItem();
            item.Text = "-- Choose Origin --";
            item.Value = "-1";
            item.Attributes.Add("style", "color:gray;");
            item.Attributes.Add("disabled", "true");
            ddlOrigin.Items.Add(item);
            List<AirPorts> lstAir = AirPorts.GetAllByRoute(false);
            foreach (AirPorts air in lstAir)
            {
                Cities city = new Cities(air.CityId);
                ddlOrigin.Items.Add(new ListItem(city.Name + " (" + air.AirPortId + ")", air.Id.ToString()));
            } 
        }

        private void BindDestination()
        {
            ddlDestination.Items.Clear();
            ddlDestination.ClearSelection();
            ListItem item = new ListItem();
            item.Text = "-- Choose Destination --";
            item.Value = "-1";
            item.Attributes.Add("style", "color:gray;");
            item.Attributes.Add("disabled", "true");
            ddlDestination.Items.Add(item);
            List<AirPorts> lstAir = AirPorts.GetAllByRoute(false);
            foreach (AirPorts air in lstAir)
            {
                Cities city = new Cities(air.CityId);
                ddlDestination.Items.Add(new ListItem(city.Name + " (" + air.AirPortId + ")", air.Id.ToString()));
            } 
        }

        private void PopulateLabels()
        {
            Title = "FPT Airlines Page - eProject";
        }

        private void LoadSettings()
        {

        }

        private void LoadParams()
        {

        }

        #region OnInit

        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new EventHandler(this.Page_Load);
            this.ddlOrigin.SelectedIndexChanged += new EventHandler(ddlOrigin_SelectedIndexChanged);
        }

        protected void ddlOrigin_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlOrigin.SelectedValue != "-1")
            {
                ddlDestination.Enabled = true;
                ListItem item = ddlDestination.Items.FindByValue("-1");
                item.Attributes.Add("style", "color:gray;");
                item.Attributes.Add("disabled", "true");
                ddlDestination.CssClass = "inputText";
            }
            else
            {
                ddlDestination.Enabled = false;
                ddlDestination.CssClass = "inputText-disabled";
            }
        }

        #endregion
    }
}